<?php
defined('IN_PHPCMS') or exit('No permission resources.');
pc_base::load_sys_class('model', '', 0);
class messages_model extends model {
	function __construct() {
		$this->db_config = pc_base::load_config('database');
		$this->db_setting = 'default';
		$this->table_name = 'messages';
		$this->_username = param::get_cookie('_username');
		$this->_userid = param::get_cookie('_userid');
		parent::__construct();
	}
	function update_messages($data, $where){
		
		return  $this->update($data, $where);
	}
	function get_list($username, $offset, $pagesize){
		
		$this->member_db = pc_base::load_model('member_model');
		
		$user = $this->member_db->get_one(array('username'=>$username));
		
		$sql = 'SELECT * from '.$this->table_name.' 
		where userid =  \''.$user['userid'].'\' order by messageid desc ';
		$sql .= " LIMIT $offset,$pagesize ";
		$this->query($sql);
		return $this->fetch_array();
	}
	function get_list_count($username){
		$sql_count = 'SELECT count(messageid) as cnt from '.$this->table_name.' 
		where userid =  \''.$user['userid'].'\' order by messageid desc';
		$this->query($sql_count);
		return  $this->fetch_array();
	}
	
}
?>